/*
 * Copyright (c) Sematext Group, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */

package route

import (
	"github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -cc $BPF_CLANG  -cflags $BPF_CFLAGS bpf ../../ebpf/route.c  -- -I../../headers
func NewCommand(logger *logrus.Logger) *cobra.Command {
	cmd := &cobra.Command{
		Use:   "route",
		Short: "Route the traffic",
		Run: func(cmd *cobra.Command, args []string) {
			dev, err := cmd.Flags().GetString("dev")
			if err != nil {
				logger.Fatal(err)
				logger.Println("must input dev！")

			}
			hook, err := NewHook()
			if err != nil {
				logger.Fatal(err)
				return
			}
			hook.listenRoute(dev)
			logger.Infof("Route the traffic")
		},
	}
	return cmd
}
